package frame.util.generator;

import java.io.File;
import java.util.regex.Matcher;

/**
 * 配置数据
 */
public class Configure {
    // 项目路径
    private String projectDir;
    // 模块包
    private String modelPackage;
    // 模块名
    private String modelName;
    //数据库表名
    private String tableName;

    private String entityFile;
    private String mapperFile;
    private String serviceFile;

    //实体名 模块名
    private String entityName;
    private String mapperName;
    private String serviceName;

    private String entityPackage;
    private String mapperPackage;
    private String servicePackage;

    // 查询配置
    private String queryName;
    private String queryPackage;

    // 作者及创建时间
    private String author;
    private String since;

    public String getModelPackage() {
        return modelPackage;
    }

    public String getModelName() {
        return modelName;
    }

    public String getTableName() {
        return tableName;
    }

    public String getEntityFile() {
        return entityFile;
    }

    public String getMapperFile() {
        return mapperFile;
    }

    public String getServiceFile() {
        return serviceFile;
    }

    public String getEntityName() {
        return entityName;
    }

    public String getMapperName() {
        return mapperName;
    }

    public String getServiceName() {
        return serviceName;
    }

    public String getEntityPackage() {
        return entityPackage;
    }

    public String getMapperPackage() {
        return mapperPackage;
    }

    public String getServicePackage() {
        return servicePackage;
    }

    public String getQueryName() {
        return queryName;
    }

    public String getQueryPackage() {
        return queryPackage;
    }

    public String getAuthor() {
		return author;
	}

	public String getSince() {
		return since;
	}


	public void setModel(String projectDir, String modelPackage, String modelName) {
        this.projectDir = projectDir;
        this.modelPackage = modelPackage;
        this.modelName = modelName;
        // 构建类名
        this.entityName = modelName;
        this.mapperName = modelName + "Mapper";
        this.serviceName = modelName + "Service";

        // 构建类包
        this.entityPackage = modelPackage + ".to";
        this.mapperPackage = modelPackage + ".mapper";
        this.servicePackage = modelPackage + ".service";

        // 构建文件存储路径
        final String dir = projectDir + "\\src\\main\\java\\" + modelPackage.replaceAll("\\.", Matcher.quoteReplacement(File.separator));
        this.entityFile = dir + "\\to\\" + modelName +".java";
        this.mapperFile = dir + "\\mapper\\" + modelName +"Mapper.java";
        this.serviceFile = dir + "\\service\\" + modelName +"Service.java";
    }

    public void setQuery(Class<?> clazz) {
        this.queryName = clazz.getSimpleName();
        this.queryPackage = clazz.getPackage().getName();
    }

	public void setAuthorSince(String author, String since) {
		this.author = author;
		this.since = since;
	}

    public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public void show(String prefix,String message) {
        System.out.println(message);
        System.out.println(prefix+"Entity类="+entityPackage+"."+entityName+"; Entity文件="+entityFile);
        System.out.println(prefix+"Mapper类="+mapperPackage+"."+mapperName+"; Mapper文件="+mapperFile);
        System.out.println(prefix+"Service类="+servicePackage+"."+serviceName+"; Service文件="+serviceFile);
    }

}
